package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.appVersion.*;
import com.smedi.ismedi.inmail.api.dto.response.AppVersionResponse;
import com.smedi.ismedi.inmail.api.dto.response.CheckVersionResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteAppVersionFeignApi;
import com.smedi.ismedi.inmail.core.application.command.*;
import com.smedi.ismedi.inmail.core.application.query.AppVersionQueryService;
import com.smedi.ismedi.inmail.core.application.query.vo.CheckVersionVo;
import com.smedi.ismedi.inmail.core.application.service.AppVersionApplicationService;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.AppVersion;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @className: AppVersionController
 * @Description: TODO
 * @version: v1.0.0
 * @author: wzx
 * @date: 2023/8/30 10:14
 */

@AllArgsConstructor
@RestController
public class AppVersionController implements RemoteAppVersionFeignApi {

    private final AdapterConverter adapterConverter;

    private final AppVersionApplicationService appVersionApplicationService;

    private final AppVersionQueryService appVersionQueryService;

    @Override
    public ResponseData<Long> create(AppVersionCreateRequest appVersionCreateRequest) {
        AppVersionCreateCommand appVersionCreateCommand = adapterConverter.appVersionCreateRequestToAppVersionCreateCommand(appVersionCreateRequest);
        return new ResponseData<>().success(appVersionApplicationService.create(appVersionCreateCommand));
    }

    @Override
    public ResponseData<Long> update(AppVersionUpdateRequest appVersionUpdateRequest) {
        AppVersionUpdateCommand appVersionUpdateCommand = adapterConverter.appVersionUpdateRequestToAppVersionUpdateCommand(appVersionUpdateRequest);
        return new ResponseData<>().success(appVersionApplicationService.update(appVersionUpdateCommand));
    }

    @Override
    public ResponseData<Boolean> remove(AppVersionRemoveRequest appVersionRemoveRequest) {
        AppVersionRemoveCommand appVersionRemoveCommand = adapterConverter.appVersionRemoveRequestToAppVersionRemoveCommand(appVersionRemoveRequest);
        appVersionApplicationService.remove(appVersionRemoveCommand);
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<Boolean> enable(AppVersionEnableRequest appVersionEnableRequest) {
        AppVersionEnableCommand appVersionEnableCommand = adapterConverter.appVersionEnableRequestToAppVersionEnableCommand(appVersionEnableRequest);
        appVersionApplicationService.enable(appVersionEnableCommand);
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<Boolean> disable(AppVersionDisableRequest appVersionDisableRequest) {
        AppVersionDisableCommand appVersionDisableCommand = adapterConverter.appVersionDisableRequestToAppVersionDisableCommand(appVersionDisableRequest);
        appVersionApplicationService.disable(appVersionDisableCommand);
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<AppVersionResponse> get(AppVersionGetRequest appVersionGetRequest) {
        AppVersionQuery appVersionQuery = adapterConverter.appVersionGetRequestToAppVersionQuery(appVersionGetRequest);
        return new ResponseData<>().success(adapterConverter.appVersionToAppVersionResponse(appVersionQueryService.get(appVersionQuery)));
    }

    @Override
    public ResponseData<List<AppVersionResponse>> list(AppVersionListRequest appVersionListRequest) {
        AppVersionQuery appVersionQuery = adapterConverter.appVersionListRequestToAppVersionQuery(appVersionListRequest);
        return new ResponseData<>().success(adapterConverter.appVersionToAppVersionResponse(appVersionQueryService.list(appVersionQuery)));
    }

    @Override
    public ResponseData<PaginationData<AppVersionResponse>> page(AppVersionPageRequest appVersionPageRequest) {
        AppVersionQuery appVersionQuery = adapterConverter.appVersionPageRequestToAppVersionQuery(appVersionPageRequest);
        Page<AppVersion> page = appVersionQueryService.page(appVersionQuery);
        return new ResponseData<>().success(adapterConverter.appVersionToAppVersionResponse(page));
    }

    @Override
    public ResponseData<CheckVersionResponse> checkVersion(AppVersionCheckVersionRequest appVersionCheckVersionRequest) {
        AppVersionCheckVersionCmd appVersionCheckVersionCmd = adapterConverter.developmentCheckVersionRequestToDevelopmentCheckVersionCmd(appVersionCheckVersionRequest);
        CheckVersionVo checkVersion = appVersionQueryService.checkVersion(appVersionCheckVersionCmd);
        return new ResponseData<>().success(adapterConverter.appVersionToAppVersionResponse(checkVersion));
    }
}